<template>
  <div>
    <div class="carbonFootprintReport">
      <!-- 标题 -->
      <div class="carbonFootprintReport-title">碳足迹报告</div>


      <!-- 条件筛选 -->
      <div class="carbonFootprintReport-condition">
        <div class="carbonFootprintReport-condition-form">
          <normal-form-plus
            :formModel="formModel"
            :config="config"
            :plus="plus"/>
        </div>
        <div class="carbonFootprintReport-condition-btn">
          <el-button>查询</el-button>
          <el-button>重置</el-button>
          <!-- <el-button @click="drawer = true">新增</el-button> -->
        </div>
      </div>


      <!-- 表格 -->
      <div class="carbonFootprintReport-report">
        <normal-table
          :tableData="tableData"
          :paginationConfig="paginationConfig"
          :tableLabel="tableLabel"
          :operationConfig="operationConfig"
          :operationList="operationList"
          @event="handleEvent"
          @changePage="changePage"></normal-table>
      </div>

      <!-- 新增碳足迹报告-抽屉 -->
      <el-drawer
        title="新增碳足迹报告"
        :visible.sync="drawer"
        :direction="'rtl'">
        <normal-form
          :formModel="addFormModel"
          :config="addConfig"
          :plus="plus"/>
        <div class="drawer-btn">
          <el-button type="primary" @click="makeSure()">确认</el-button>
        </div>

      </el-drawer>


    </div>
  </div>
</template>

<script>
import NormalForm from '@/components/NormalForm'
import NormalTable from '@/components/NormalTable'
import NormalFormPlus from '@/components/NormalFormPlus'

export default {
  name: 'carbonFootprintReport',
  components: {
    NormalTable,
    NormalFormPlus,
    NormalForm
  },
  mounted() {
    this.initTable()
  },
  data() {
    return {
      focusId: '',
      // 新增碳足迹报告-数据
      addFormModel: {},
      addConfig: [
        {
          id: '1',
          edit: true,
          type: 'select',
          model: 'type',
          name: '语言类型',
          props: {
            placeholder: "语言类型",
            options: [
              {label: '中文', value: '1'},
              {label: '英文', value: '2'},
              {label: '韩文', value: '3'}
            ]
          }
        }
      ],
      plus: {},
      drawer: false,
      formModel: {
        selection1: '',
        selection2: '',
        selection3: '',
      },
      config: [
        {
          id: 1,
          items: [
            {
              id: '1',
              edit: true,
              type: 'input',
              span: 6,
              model: 'modelLevel',
              name: '',
              props: {
                placeholder: "报告名称",

              }
            },
            {
              id: '2',
              edit: true,
              type: 'select',
              span: 6,
              model: 'modelLevel',
              name: '',
              props: {
                placeholder: "核算周期",
                options: [
                  {value: '1', label: '1'},
                  {value: '2', label: '2'}
                ]
              }
            }
          ]
        },
      ],
      plus: {},
      tableData: [],
      paginationConfig: {
        total: 100,
        page: 1,
        pageSize: 10,
        show: true
      },
      operationList: [
        {
          name: '查看',
          order: 1,
          buttonClass: 'primary',
          plus: {}
        },
        {
          name: '下载',
          order: 2,
          buttonClass: 'primary',
          plus: {}
        },
        {
          name: '删除',
          order: 3,
          buttonClass: 'primary',
          plus: {}
        }
      ],
      operationConfig: {select: false},
      tableLabel: [
        {
          prop: "order",
          label: "序号",
          width: 70
        },
        {
          prop: "name",
          label: "报告名称",
          width: 200
        },
        {
          prop: "personInfo",
          label: "报告负责人信息"
        },
        {
          prop: "personMobile",
          label: "报告负责人电话",
          width: 200
        },
        {
          prop: "personEmail",
          label: "报告负责人邮箱",
          width: 200
        },
        {
          prop: "@createTime",
          label: "创建时间",
          width: 200
        }
      ],

    }
  },
  methods: {
    makeSure() {
      this.drawer = false
      this.createReportDownLoad();
    },
    // 下载报告
    createReportDownLoad() {
      this.$API.product.createReportDownLoad({
        reportId: this.focusId,
        type: this.addFormModel.type
      }).then(response => {
        const a = document.createElement('a')
        a.href = response.data
        a.download = '温室气体报告.docx' // 下载后文件名
        a.style.display = 'none'
        document.body.appendChild(a)
        a.click() // 点击下载
        document.body.removeChild(a) // 下载完成移除元素
      })
    },
    initTable() {
      this.$API.product.getReportByPage({
        pageNo: 1,
        pageSize: 100,
      }).then(response => {
        this.tableData = response.data.list

      })
    },
    // 处理表格点击事件
    handleEvent(order, row) {
      if (order === 1) {

      } else if (order === 2) {
        this.drawer = true;
        this.focusId = row.id
      }
    },
    // 分页点击事件
    changePage() {

    }
  }
}
</script>

<style lang="less" scoped>
.drawer-btn {
  margin-left: 150px;
}

.carbonFootprintReport {

  height: 680px;
  overflow: hidden;
  padding: 15px 10px;
  // 标题
  .carbonFootprintReport-title {
    font-size: 16px;
    font-weight: bold;
  }

  .carbonFootprintReport-condition {
    display: flex;

    .carbonFootprintReport-condition-form {
      flex: 3;
    }

    .carbonFootprintReport-condition-btn {
      flex: 1;
    }
  }

  // 核算报告表格
  .carbonFootprintReport-report {
    .carbonFootprintReport-history-title {
      font-size: 14px;
    }
  }
}
</style>
